package ua.pp.bizon.cripto.authorization;

import ua.pp.bizon.cripto.utils.ExceptionHandler;

public class CredentialsFactory {

    private ExceptionHandler handler;

    private UI ui;

    public UI getUi() {
        return ui;
    }

    public void setUi(UI ui) {
        this.ui = ui;
    }

    @SuppressWarnings("deprecation")
    public Credentials load() {
        try {
            return Credentials.init(getUi());
        } catch (Exception e) {
            if (getHandler() != null) {
                getHandler().handle(e);
            } else {
                e.printStackTrace();
            }
            throw new RuntimeException(e);
        }
    }

    public ExceptionHandler getHandler() {
        return handler;
    }

    public void setHandler(ExceptionHandler handler) {
        this.handler = handler;
    }

}
